//index.js
//获取应用实例
import { ARTICLE_INDEX } from '../../utils/url.js';
import getIn from '../../sdk/utils/getIn';
import {API_ARTICLE_CATE} from "../../sdk/business/url";
import {showSuccess,showFail} from '../../utils/util';
Page({
  data: {
    bannerList:[
        {id: 1, pic: 'https://xrmwl.com/wl/img/banner-1.png'},
        {id: 2, pic: 'https://xrmwl.com/wl/img/banner-2.png'},
        {id: 3, pic: 'https://xrmwl.com/wl/img/banner-3.png'},
    ],
      menuList:[{pic:'', cate_name: '搬家'},
                {pic:'', cate_name: '货运'},
                {pic:'', cate_name: '企业搬迁'},
                {pic:'', cate_name: '劳动力派遣'},
                {pic:'', cate_name: '仓储'},
                {pic:'', cate_name: '关于我们'}]
  },
  onLoad () {
      this.menuList()
  },
    toDetail(e) {
        const id = getIn(e.currentTarget, ['id']);
        const nature = getIn(e.currentTarget.dataset, ['nature']);
        const cate_name = getIn(e.currentTarget.dataset, ['cate_name']);
        const queryString = `id=${id}&nature=${nature}&cate_name=${cate_name}`;
        global.navigateHelper.navigateTo({ pathname: ARTICLE_INDEX, queryString });
    },
    menuList() {
        const token = wx.getStorageSync('token');
        getApp().userInfo().then((res) => {
          global.request(API_ARTICLE_CATE, {token}, (code, res) => {
            if (code = 'SUCCESS') {
                const menuList = getIn(res.data, ['list']);
                // menuList = menuList && menuList.map((x, i) => {
                //     x.pic = `/static/images/menu${i}.png`;
                //     return x;
                // })
                this.setData({ menuList });
                wx.hideLoading()
            } else if(code == 'FAIL') {
                showFail(res.msg)
                wx.hideLoading()
            }
        });
        })
        
    },
    toPhone() {
      wx.makePhoneCall({
        phoneNumber: '4000028856'
      })
    },
    onPullDownRefresh() {
      this.menuList()
    },
    onShareAppMessage() {
      return {
      title: '安逸搬家',
      desc: '只有专业才能安逸，安逸物流帮您拓展天地',
      path: '/pages/index/index'
    }
    }
})
